package Cinema.Tests;

import static org.junit.Assert.*;

import java.util.Set;

import org.junit.Test;
import org.w3c.dom.Document;

import Utils.XmlParseHelper;

import Cinema.CinemaEntities.BigSite;
import Cinema.CinemaEntities.Location;
import Cinema.CinemaEntities.Site;
import Cinema.CinemaEntities.Theater;
import Cinema.DataLayer.XmlBackup;
import Exceptions.BadArgumentException;
import Exceptions.DataAccessException;

public class SiteTest implements IXmlParsableTest{

	@Test
	@Override
	public void test_getXml() throws DataAccessException{
		Site testSite = new BigSite("NoPlanet", new Location(321,654), "Gaza");
		Document tesDoc = XmlBackup.createDocFromXmlParsableObject(testSite);
		Document controlDoc = XmlParseHelper.getDocumentFromFile(".\\tests\\testXml\\SiteTest.xml");
		boolean isEq = XmlBackupTest.isDocumentsSimilar(controlDoc, tesDoc);
		assertTrue(isEq);
	}
	
	@Test
	@Override
	public void test_initFromXml() throws BadArgumentException, DataAccessException{
		Site controlSite = new BigSite("DaPlanet", new Location(1, 1), "Moscow");
		Site testSite = new BigSite(true, XmlParseHelper.getDocumentFromFile(".\\tests\\testXml\\SiteTest2.xml").getDocumentElement());
		assertTrue(controlSite.checkEquals(testSite));
		
		Site controlSite2 = new BigSite("DaPlanet", new Location(7, 9), "Shchem");
		Set<Theater> theaterList = controlSite2.getTheaters();
		Theater theater = new Theater("room79", new Location(7, 9), 4, 8, "Shchem");
		theaterList.add(theater);
		Site testSite2 = new BigSite(true, XmlParseHelper.getDocumentFromFile(".\\tests\\testXml\\SiteTest3.xml").getDocumentElement());
		//checking that site city and location taken from site element and not from theaters in backup case
		assertFalse(controlSite2.checkEquals(testSite2));
		
		controlSite2 = new BigSite("DaPlanet", new Location(1, 1), "Moscow");
		theaterList = controlSite2.getTheaters();
		theater = new Theater("room79", new Location(7, 9), 4, 8, "Shchem");
		theaterList.add(theater);
		assertTrue(controlSite2.checkEquals(testSite2));
		
		Site testSite3 = new BigSite(false, XmlParseHelper.getDocumentFromFile(".\\tests\\testXml\\SiteTest4.xml").getDocumentElement());
		Site controlSite3 = new BigSite("yesPlanet_Site", new Location(234, 435), "Haifa");
		Set<Theater> theaterList3 = controlSite2.getTheaters();
		theater = new Theater("Hall0", new Location(234, 435), 76, 88, "Haifa");
		theaterList3.add(theater);
		theater = new Theater("Hall1", new Location(234, 435), 101, 46, "Haifa");
		theaterList3.add(theater);
		assertTrue(controlSite3.checkEquals(testSite3));
	}

	public void test_SmallSuteConstractor(){
	}
}
